<style lang="less">
@import './main.less';
</style>
<template>
    <div class="main" :class="{'main-hide-text': shrink}" ref="mainBody">
        <div class="sidebar-menu-con" :style="{width: shrink?'60px':'200px', overflow: shrink ? 'visible' : 'auto'}">
            <div class="layout-logo"><img style="height:40px" src="../assets/logo_quanpin.png" key="max-logo" />
                <span class="bate">传音供应链</span>
            </div>
            <CpMenu ref="cpMenu" :before-push="beforePush" :open-names="openedSubmenuArr" :menu-list="menuList" />
            <div style="background-color:#F0F0F0;width:200px;position: fixed;padding: 5px;bottom: 0px;left: 0px;text-align: center;">
                <a style="font-size: 16px;" target="_blank" href="https://www.taobao.com/markets/cnwww/print">菜鸟打印控件下载</a>
            </div>
        </div>
        <div class="main-header-con" :style="{paddingLeft: shrink?'60px':'200px'}">
            <div class="main-header">
                <!--  <div class="navicon-con">
                    <i class="md-arrow-back" size="32" :style="{lineHeight:'40px',transform: 'rotateZ(' + (this.shrink ? '-180' : '0') + 'deg)'}" @click="toggleClick" />
                </div> -->
                <div class="header-middle-con">
                    <TopMenu />
                </div>
            </div>
            <div style="position: relative;">
                <custom-breadcrumb :currentPath="currentPath">
                </custom-breadcrumb>
            </div>
            <div class="tags-con">
                <tags-page-opened :pageTagsList="pageTagsList"></tags-page-opened>
            </div>
        </div>
        <div class="single-page-con" :style="{left: shrink?'60px':'200px'}">
            <div class="single-page" style="padding-bottom: 40px;">
                <keep-alive :include="cachePage">
                    <router-view></router-view>
                </keep-alive>
                <div style="padding:5px 10px;font-size:14px;position: fixed;bottom: 5px;left: 200px;right: 200px;text-align: center;z-index: 1"> <a href="http://www.roctc.com/" target="_blank">Copyright 2022-2025 © 泉州市传音供应链管理有限公司</a>
                </div>
            </div>
        </div>
        <el-backtop target=".single-page-con" :bottom="50">
            <div style="{
        height: 100%;
        width: 100%;
        background-color: #f2f5f6;
        box-shadow: 0 0 6px rgba(0,0,0, .12);
        text-align: center;
        line-height: 40px;
        color: #1989fa;
      }">
                <i class="el-icon-top"></i>
            </div>
        </el-backtop>
    </div>
</template>
<script>
import CpMenu from '../Menu.vue'
import TopMenu from '../TopMenu.vue'
import util from "@/utils/util"
import TagsPageOpened from '@/components/Nav/TagsPageOpened.vue'
import CustomBreadcrumb from '@/components/Nav/CustomBreadcrumb.vue'
export default {
    name: "Main",
    data() {
        return {
            shrink: false,
            avatorPath: '',
            interval: null,
            openedSubmenuArr: this.$store.state.app.openedSubmenuArr

        };
    },
    components: {
        CpMenu,
        TopMenu,
        TagsPageOpened,
        CustomBreadcrumb
    },
    create: function() {
        this.$store.commit('setOpenedList');
    },
    computed: {
        userName() {
            // return this.$store.state.user.userName;
            return localStorage.userName;
        },
        merchId() {

            return localStorage.userId;
        },
        menuList() {
            return this.$store.state.app.menuList;
        },
        pageTagsList() {

            return this.$store.state.app.pageOpenedList; // 打开的页面的页面对象
        },


        currentPath() {
            return this.$store.state.app.currentPath; // 当前面包屑数组
        },

        cachePage() {
            return this.$store.state.app.cachePage;
        },
        lang() {
            return this.$store.state.app.lang;
        },
        menuTheme() {
            return this.$store.state.app.menuTheme;
        },
        mesCount() {
            return this.$store.state.app.messageCount;
        }
    },
    mounted: function() {

        var me = this;
         me.getNotify();
        // me.interval = setInterval(function() { me.getNotify() }, 10000);

    },
    beforeRouteLeave(to, from, next) {

        if (to.name == "Login" && this.interval) {
            window.clearInterval(this.interval);

        }


        next();
    },
    beforeRouteUpdate(to, from, next) {



        next();
    },
    beforeRouteEnter(to, from, next) {

        next();
    },
    watch: {
        '$route'(to) {

            this.$store.commit('setCurrentPageName', to.name);

            let pathArr = util.setCurrentPath(this, to.name);
            if (pathArr.length > 2) {
                this.$store.commit('addOpenSubmenu', pathArr[1].name);
            }
            this.checkTag(to.name);
            localStorage.currentPageName = to.name;
        }
    },
    methods: {
        toggleClick() {
            this.shrink = !this.shrink;
        },
        handleClickUserDropdown(name) {
            // if (name === 'ownSpace') {
            //     util.openNewPage(this, 'ownspace_index');
            //     this.$router.push({
            //         name: 'ownspace_index'
            //     });
            // } else if (name === 'loginout') {
            //     // 退出登录
            //     this.$store.commit('logout', this);
            //     this.$store.commit('clearOpenedSubmenu');
            //     this.$router.push({
            //         name: 'login'
            //     });
            // }
        },
        beforePush(name) {
            // if (name === 'accesstest_index') {
            //     return false;
            // } else {
            //     return true;
            // }
            return true;
        },
        checkTag(name) {
            let openpageHasTag = this.pageTagsList.some(item => {
                if (item.name === name) {
                    return true;
                }
            });
            if (!openpageHasTag) { //  解决关闭当前标签后再点击回退按钮会退到当前页时没有标签的问题
                util.openNewPage(this, name, this.$route.params || {}, this.$route.query || {});
            }
        },
        getNotify: function() {
            var me = this;
            let token = localStorage.getItem('token');

            if (token == "" || token == undefined) {
                return;
            }
            me.$http.post('/stastis/notify.do').then(response => {
                if (response.status == 0) {
                    var counts = response.obj;
                    //内部
                    // 提交store
                    me.$store
                        .dispatch("setCount", counts);

                    // me.$refs['cpMenu'].toMySignCount = counts.toMySignCount;
                    // me.$refs['cpMenu'].toMyOutgoingCount = counts.toMyOutgoingCount;

                    me.$refs['cpMenu'].billCount = counts.billCount + counts.billCountBack + counts.billCountSign + counts.billCountShip;
                    // me.$refs['cpMenu'].waybillLocalCount = counts.toSignLocalCount + counts.toOutgoingLocalCount;

                    //代发异常
                    me.$refs['cpMenu'].errorCount = counts.toSignLocalCount + counts.toOutgoingLocalCount;


                    me.$refs['cpMenu'].outgoReadship = counts.outgoReadship;
                    me.$refs['cpMenu'].outgoTryship = counts.outgoTryship;
                    me.$refs['cpMenu'].waybillCount = counts.toSignCount + counts.toOutgoingCount;

                    me.$refs['cpMenu'].lazadaWaybillCount = counts.toLazadaSignCount + counts.toLazadaOutgoingCount;

                    me.$refs['cpMenu'].tiktokWaybillCount = counts.toTkSignCount + counts.toTkOutgoingCount;

  me.$refs['cpMenu'].temuWaybillCount = counts.toTmSignCount + counts.toTmOutgoingCount;

                    me.$refs['cpMenu'].logisticsErrorCount = counts.logisticsErrorCount;

                    me.$refs['cpMenu'].orderErrorCount = counts.orderErrorCount;

                    me.$refs['cpMenu'].returnCount = counts.returnCount + counts.returnToCount;

                    me.$refs['cpMenu'].returnToCountToDo = counts.returnToCountToDo;

                    me.$refs['cpMenu'].purchareCount = counts.purchareCount;
                    me.$refs['cpMenu'].purchareShip = counts.purchareShip;
                    me.$refs['cpMenu'].purchareDelivered = counts.purchareDelivered;
                    me.$refs['cpMenu'].storageChange = counts.storageChange;

                    me.$refs['cpMenu'].toXiapiReturn = counts.toReturnRequest + counts.toReturnProcess + counts.toReturnJud;
                    me.$refs['cpMenu'].virWaybillCount = counts.toVirOutgoingCount + counts.toVirSignCount;

                } else {

                }

            }).catch(response => {

            });
        }
    }
}
</script>
<style scoped>
.optButton {
    float: right;
    margin-right: 10px;
}

.bate {
    position: absolute;
    bottom: 5px;
    right: 5px;
    font-size: 14px;
}
</style>